<div class="guide_service_dialog" id="single">
    <!--使用套餐内条数-->
    <div class="guide_jobs_about">
        <div class="guide_btn_group alone">
            <div class="btn_guide" id="confirm_setmeal_submit">确定下载</div>
        </div>
        
    </div>
    
</div>
<input type="hidden" id="to_detail" value="{$_GET['to_detail']}">
<script type="text/javascript">
    $('.head_tab,.change_tab').click(function(event) {
        var data = $(this).attr('data');
        $(".guide_service_dialog").hide();
        $("#"+data).show();
    });
    $("#J_integralforcash_input").keyup(function(){
        var thisvalue = $(this).val();
        var mypoints = parseInt("{$mypoints}");
        var current_points = parseInt("{$refresh_points}");
        var minpointsValue = mypoints >= current_points ? current_points : mypoints;
        if (thisvalue > minpointsValue) {
            $(this).val(minpointsValue);
        }
        if(parseInt($(this).val())>0){
            $("#is_deductible").val(1);
        }else{
            $("#is_deductible").val(0);
        }
        $("#deductible").val($(this).val());
        $("#pay_cash").text((parseInt("{:C('qscms_download_resume_price')}")-parseFloat($(this).val()/parseInt("{:C('qscms_payment_rate')}"))).toFixed(2));
        $('#J_integralforcashvalue').text(parseFloat($(this).val()/parseInt("{:C('qscms_payment_rate')}")).toFixed(2));
    });
    $(".cash_pay_submit").click(function(){
        $("#payment_name").val($(this).attr('payment'));
        $("#payment_name_increment").val($(this).attr('payment'));
        var formid = $(this).attr('form_id');
        var action_url = $(this).attr('data-action');
        if($(this).attr('payment')=='wxpay'){
            var qsDialog = $("#"+formid).dialog({
                title: '微信支付',
                loading:true,
                footer:false
            });
            $.ajax({
                cache: true,
                type: "POST",
                url:action_url,
                data:$('#'+formid).serialize(),
                dataType:"json",
                success: function(result) {
                    if(result.status==1){
                        qsDialog.setContent("<img src='"+result.data+"' alt='扫描二维码' width='250' height='250' />");
                        window.setInterval(run, 5000);
                    }else{
                        qsDialog.setContent(result.msg);
                        return false;
                    }
                }
            });
        }else{
            $("#"+formid).submit();
        }
    });
    $("#confirm_setmeal_submit").click(function(){
        var url = "{:U('CompanyService/resume_download')}";
        var resume_id = "{$resume_id}";
        $.post(url,{rid:resume_id},function(result){
            if(result.status==1){
                disapperTooltip('success', '下载简历成功！');
                if($("#to_detail").val()==1){
                    setTimeout(function () {
                        window.location.href="{:url_rewrite('QS_resumeshow',array('id'=>$resume_id))}";
                    }, 2000);
                }else{
                    setTimeout(function () {
                        window.location.reload();
                    }, 2000);
                }
            }else{
                disapperTooltip("remind",result.msg);
                return false;
            }
        },'json');
    });
    $("#confirm_points_submit").click(function(){
        var url = "{:U('CompanyService/resume_download')}";
        var resume_id = "{$resume_id}";
        $.post(url,{rid:resume_id},function(result){
            if(result.status==1){
                disapperTooltip("success",result.msg);
                if($("#to_detail").val()==1){
                    setTimeout(function () {
                        window.location.href="{:url_rewrite('QS_resumeshow',array('id'=>$resume_id))}";
                    }, 2000);
                }else{
                    setTimeout(function () {
                        window.location.reload();
                    }, 2000);
                }
            }else{
                disapperTooltip("remind",result.msg);
                return false;
            }
        },'json');
    });
    select_pay_type();
    // 套餐列表点击
    var $radiobj = $('.J_radioitme_order');
    $radiobj.live('click', function(event) {
        $("#project_id").val($(this).attr("project_id"));
        $("#total_points").val($(this).attr("need_points"));
        select_pay_type();
    });
    function select_pay_type(){
        var mypoints = parseInt("{$mypoints}");
        var current_points = parseInt($("#total_points").val());
        if(mypoints<current_points){
            $(".points_pay_increment").hide();
            $(".cash_pay_increment").show();
            $('#J_integralforcash_input_increment').val(mypoints);
            $('#deductible_increment').val(mypoints);
        }else{
            $(".points_pay_increment").show();
            $(".cash_pay_increment").hide();
            $('#J_integralforcash_input_increment').val(current_points);
            $('#deductible_increment').val(current_points);
        }
        $(".need_points").html(current_points);
        if(parseInt($('#J_integralforcash_input_increment').val())>0){
            $("#is_deductible_increment").val(1);
        }else{
            $("#is_deductible_increment").val(0);
        }
        var need_cash = current_points/parseInt("{$payment_rate}");
        $("#need_cash").val(need_cash.toFixed(2));
        $("#amount").val(need_cash.toFixed(2));
        $('#J_integralforcashvalue_increment').text(($('#J_integralforcash_input_increment').val()/parseInt("{$payment_rate}")).toFixed(2));
        if (parseInt($('#J_integralforcashvalue_increment').html())>0) {
            $("#pay_cash_increment").text((need_cash-parseFloat($('#J_integralforcashvalue_increment').text()).toFixed(2)).toFixed(2));
            $('#amount').val((parseFloat($('#need_cash').val())-parseFloat($('#J_integralforcashvalue_increment').text())).toFixed(2));
        } else {
            $("#pay_cash_increment").html(need_cash.toFixed(2));
            $('#amount').val(need_cash.toFixed(2));
        }
    }
    $("#J_integralforcash_input_increment").keyup(function(){
        var thisvalue = $(this).val();
        var mypoints = parseInt("{$mypoints}");
        var current_points = parseInt($("#total_points").val());
        var minpointsValue = mypoints >= current_points ? current_points : mypoints;
        if (thisvalue > minpointsValue) {
            $(this).val(minpointsValue);
        }
        if(parseInt($(this).val())>0){
            $("#is_deductible_increment").val(1);
        }else{
            $("#is_deductible_increment").val(0);
        }
        var need_cash = current_points/parseInt("{$payment_rate}");
        $("#need_cash").val(need_cash.toFixed(2));
        $("#deductible_increment").val($(this).val());
        $("#pay_cash_increment").text((need_cash-$(this).val()/parseInt("{$payment_rate}")).toFixed(2));
        $('#J_integralforcashvalue_increment').text(($(this).val()/parseInt("{$payment_rate}")).toFixed(2));
        $('#amount').val((parseFloat($('#need_cash').val())-parseFloat($('#J_integralforcashvalue_increment').text())).toFixed(2));
    });
    function run(){
        $.getJSON("{:U('CompanyService/check_weixinpay_notify')}",function(result){
            if(result.status==1){
                window.location.href="{:url_rewrite('QS_resumeshow',array('id'=>$resume_id))}";
            }
        });
    }
    $("#points_convert").click(function(){
        ajax_pay('{$cat}','points');
    });
    function ajax_pay(type,pay_type){
        var project_id = $("#project_id").val();
        var resume_id = $("#resume_id_increment").val();
        var payment_name = "points";
        $.post("{:U('CompanyService/increment_add_save')}",{pay_type:pay_type,service_type:type,project_id:project_id,payment_name:payment_name,resume_id:resume_id},function(result){
            if(result.status==1){
                disapperTooltip("success", "兑换成功！");
                var url = "{:U('CompanyService/resume_download')}";
                var resume_id = "{$resume_id}";
                $.post(url,{rid:resume_id},function(result){
                    if(result.status==1){
                        if($("#to_detail").val()==1){
                            window.location.href="{:url_rewrite('QS_resumeshow',array('id'=>$resume_id))}";
                        }else{
                            window.location.reload();
                        }
                    }else{
                        disapperTooltip("remind",result.msg);
                        return false;
                    }
                },'json');
            }
        },'json');
    }
</script>